﻿using System;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Media;

namespace ViewLibrary.Controls
{
	public class TPasswordBox : UserControl
	{
		private PasswordBox _passwordBox = new PasswordBox();
		[Category("Content")]
		public string Password
		{
			get { return _passwordBox.Password; }
			set { _passwordBox.Password = value; }
		}

		public TPasswordBox()
		{
			_passwordBox.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
			_passwordBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
			_passwordBox.GotFocus += _passwordBox_GotFocus;
			_passwordBox.LostFocus += PasswordBox_LostFocus;
			this.AddChild(_passwordBox);
		}

		private Brush _normalBackground = Brushes.White;
		[Category("Brush")]
		public Brush NormalBackground
		{
			get { return _normalBackground; }
			set { _normalBackground = value; }
		}

		private Brush _focusedBackground = Brushes.Beige;
		[Category("Brush")]
		public Brush FocusedBackground
		{
			get { return _focusedBackground; }
			set { _focusedBackground = value; }
		}

		protected override void OnGotFocus(System.Windows.RoutedEventArgs e)
		{
			base.OnGotFocus(e);
			_passwordBox.Focus();
		}
		private void _passwordBox_GotFocus(object sender, System.Windows.RoutedEventArgs e)
		{
			_passwordBox.Background = _focusedBackground;
		}
		private void PasswordBox_LostFocus(object sender, System.Windows.RoutedEventArgs e)
		{
			_passwordBox.Background = _normalBackground;
		}
	}
}